package miku.firstgame.model
{
	import miku.firstgame.entity.Bomb;
	import miku.firstgame.model.gold.UserOrderVo;
	import miku.firstgame.model.gold.interfaces.ICard;

	public class Me extends User
	{
		private static var _instance:Me;

		//当前所在的房间id
		private var _room:Room;

		private var contactUsers:Vector.<User>;

		//TODO 需要将以下属性专门提出到一个gameroom类中

		/**
		 * 当前轮到谁,下面4个都是存储自身信息
		 * */
		public var currentTurn:int;

		//是否是个好人
		public var isGood:Boolean;

		public var cards:Vector.<ICard>;
		//
		public var orders:Vector.<UserOrderVo>;

		public function Me(id:int)
		{
			super(id);
			contactUsers = new Vector.<User>();
		}

		/**
		 * 当前用户是否能够操作
		 * */
		public function get canDoAction():Boolean
		{
			if (currentTurn == id)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		public function get isAllContactUserReady():Boolean
		{
			for each (var user:User in contactUsers)
			{
				if ((!(user is Me)) && !user.isReady)
				{
					return false;
				}
			}
			return true;
		}

		public function get room():Room
		{
			return _room;
		}

		public function set room(value:Room):void
		{
			_room = value;
		}

		public static function get Instace():Me
		{
			if (_instance == null)
			{
				_instance = new Me(-1);
				_instance.addContactUser(_instance);
			}
			return _instance;
		}

		public function addContactUser(user:User):User
		{
			contactUsers.push(user);
			return user;
		}

		public function getContactUsers():Vector.<User>
		{
			return contactUsers;
		}

		public function setContactUsers(users:Vector.<User>):void
		{
			contactUsers = users;
		}

		public function removeContactUser(userId:int):User
		{
			var length:int = contactUsers.length;

			for (var i:int = 0; i < length; i++)
			{
				var user:User = contactUsers[i];
				if (user.id == userId)
				{
					contactUsers.splice(i, 1);
					return user;
				}
			}

			return null;
		}

		public function clearContactUsers():void
		{
			contactUsers = new Vector.<User>();
			contactUsers.push(Me.Instace);
		}

	}
}
